package com.iseastar.guojiang.station;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.iseastar.guojiang.BaseActivity;
import com.iseastar.guojiang.app.Intents;
import com.iseastar.guojiang.logic.AppLogic;
import com.iseastar.guojiang.model.StationParcelBean;
import com.iseastar.guojiang.order.OrderExceptionActivity;
import com.iseastar.guojiang.order.OrderRefuseActivity;
import com.shouhuobao.station.R;

/**
 * 驿站、裹将核对、包裹详情
 *
 * @author coffee<br>
 *         2016-12-3上午11:26:50
 */
public class StationParcelDetailsActivity extends BaseActivity implements OnClickListener {

	private StationParcelBean item;

	@Override
	@SuppressLint("ResourceAsColor")
	protected void onCreate(Bundle savedInstanceState) {
		item = (StationParcelBean) getIntent().getSerializableExtra("item");
		super.onCreate(savedInstanceState);
	}

	@Override
	protected void findViewById() {
		setContentView(R.layout.station_parcel_details);
		super.findViewById();
		getAppTitle().setCommonTitle("包裹详情");

		TextView username = (TextView) findViewById(R.id.station_username);
		TextView userPhone = (TextView) findViewById(R.id.station_userPhone);
		TextView bagCode = (TextView) findViewById(R.id.station_bagCode);
		TextView goodsType = (TextView) findViewById(R.id.station_goodsType);
		TextView arriveTime = (TextView) findViewById(R.id.station_arriveTime);
		ImageView goodsImage = (ImageView) findViewById(R.id.station_goodsImage);
		findViewById(R.id.station_refuse).setOnClickListener(this);
		findViewById(R.id.station_exception).setOnClickListener(this);
		findViewById(R.id.station_dial).setOnClickListener(this);
		//
		if (item == null) {
			showToast("item为空");
			finish();
		} else {
			username.setText("用户昵称: " + item.getSenderName());
			userPhone.setText("用户电话: " + item.getSenderPhone());
			if(isNotEmpty(item.getBagCode())) {
				bagCode.setText("投递袋编号: " + item.getBagCode());
			}else {
				bagCode.setText("投递袋编号: " + getResources().getString(R.string.parcel_nobag_code));
			}
			goodsType.setText("物品类型: " + item.getCategory());
			arriveTime.setText("到店时间: " + item.getPostTime());
			//
			AppLogic.loadImage(item.getParcelImgUrl(), goodsImage);
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			// 拒收
			case R.id.station_refuse:
				Intent intent = new Intent();
				intent.setClass(getContext(), OrderRefuseActivity.class);
				intent.putExtra("itemId", item.getParcelId());// 包裹id
				startActivityForResult(intent, 101);
				break;
			// 异常申报
			case R.id.station_exception:
				intent = new Intent();
				intent.setClass(getContext(), OrderExceptionActivity.class);
				intent.putExtra("item", item);//
				startActivityForResult(intent, 102);
				break;
			// 拨打电话
			case R.id.station_dial:
				Intents.dialOrCall(item.getSenderPhone());
				break;
		}
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		// 拒收
		if (requestCode == 101 && resultCode == RESULT_OK) {
			setResult(RESULT_OK);
			finish();
		}
		// 异常申报
		else if (requestCode == 102 && resultCode == RESULT_OK) {
			setResult(RESULT_OK);
			finish();
		} else {
			super.onActivityResult(requestCode, resultCode, data);
		}
	}
}
